package cn.sskxyz.security.authorization.service;

import cn.sskxyz.mybatis.mode.Page;
import cn.sskxyz.security.authorization.dao.AuthorizationDao;
import cn.sskxyz.security.authorization.model.Resource;
import cn.sskxyz.security.authorization.model.Role;
import cn.sskxyz.security.authorization.model.RoleResource;
import cn.sskxyz.security.authorization.model.RoleUser;
import cn.sskxyz.security.core.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuthorizationService {
    @Autowired
    private AuthorizationDao authorizationDao;

    public void addRole(Role role) {
        authorizationDao.insertRole(role);
    }

    public void addRoleUser(RoleUser roleUser) {
        authorizationDao.insertRoleUser(roleUser);
    }

    public void addRoleResource(RoleResource roleResource) {
        authorizationDao.insertRoleResource(roleResource);
    }

    public Page<List<Role>> queryRoleList(int currentPage, int pageSize) {
        Page page = new Page(currentPage, pageSize);
        List<Role> data = authorizationDao.selectRoleList(page);
        page.setData(data);
        return page;
    }

    public List<User> queryUserListByRoleId(Long roleId) {
        return authorizationDao.selectUserListByRoleId(roleId);
    }

    public List<Role> queryUserRolesByUserId(Long userId) {
        return authorizationDao.selectUserRolesByUserId(userId);
    }

    public List<Resource> queryResourceListByRoleId(Long roleId) {
        return authorizationDao.selectResourceListByRoleId(roleId);
    }

    public List<Resource> selectUserPermissionByUserId(Long userId) {
        return authorizationDao.selectUserPermissionByUserId(userId);
    }
}
